import com.sun.security.jgss.GSSUtil;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        int[][] arr={{1,2,3},{4,5,6}};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("============");

        for (int[] temp:arr) {
            for (int x:temp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println("============");

        System.out.println(Arrays.deepToString(arr));
        int[][] arr1=new int[][]{{1,2,3},{4,5,6}};
        int[][] arr2=new int[2][3];

        //不规则的二维数组
        int[][] arr3=new int[2][];
        arr3[0]=new int[5];
        arr3[1]=new int[8];
        for (int i = 0; i < arr3.length; i++) {
            for (int j = 0; j < arr3[i].length; j++) {
                System.out.print(arr3[i][j]+" ");
            }
            System.out.println();
        }

    }


    public static boolean func2(int[] arr){
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]%2==0){
                count=0;
            }else{
                count++;
                if(count==3){
                    return true;
                }
            }
        }
        return false;
    }
    public static void main17(String[] args) {
        int[] arr={1,2,34,3,4,5,7,23,12};
        boolean ret=func2(arr);
        System.out.println(ret);
    }
    public static void func1(int[] arr){
        int left=0;
        int right=arr.length-1;
        while (left<right){
            while(left<right&&arr[left]%2==1){  //left<right是为了防止越界
                left++;
            }
            while(left<right&&arr[right]%2==0){
                right--;
            }
            swap(arr,left,right);
        }
    }
    public static void swap(int[] arr,int i,int j){
        int temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }
    public static void main16(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,9};
        func1(arr);
        Arrays.sort(arr,0,5);
//        Arrays.sort(arr,6,9);
        System.out.println(Arrays.toString(arr));
    }

    public static void main15(String[] args) {
        int[] arr={2,2,1,1,1,2,2};
        Arrays.sort(arr);
        System.out.println(arr[arr.length/2]);
    }

    public static int[] FindNumtag(int[] arr,int targe){
        int flag=0;
        int[] FindTag={-1,-1};
        if(arr==null||arr.length<2){
            return FindTag;
        }
        for (int i = 0; i < arr.length; i++) {

            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]+arr[j]==targe){
                    FindTag[0]=i;
                    FindTag[1]=j;
                    flag=1;
                    break;
                }
            }
            if(flag==1){
                break;
            }
        }
        return FindTag;
    }
    public static void main14(String[] args) {
        int[] arr={2,11,7,15};
        int targe=9;
        int[] Findtag=FindNumtag(arr,targe);
        System.out.println(Arrays.toString(Findtag));

    }

    public static boolean checkNum(int[] arr){
        for (int i = 2; i < arr.length; i++) {
            if(arr[i]%2==1&&arr[i-1]%2==1&&arr[i-2]%2==1){
                return true;
            }
        }
        return false;
    }

    public static void main13(String[] args) {
        int[] arr={1,2,34,3,4,5,7,23,12};
        boolean ret=checkNum(arr);
        System.out.println(ret);
    }


    public static int findMaxNumCount(int[] arr){
        Arrays.sort(arr);
        int max=0;
        int count=1;
        int MaxNumCount=0;
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]==arr[i-1]) {
                count++;
            }else{
                count=1;
            }
            if(max<count){
                max=count;
                MaxNumCount=arr[i];
            }
        }
        return MaxNumCount;
    }
    public static void main12(String[] args) {
        int[] arr={2,2,1,1,1,2,2};
        int ret=findMaxNumCount(arr);
        System.out.println(ret);
    }

    public static int theOnlyNum(int[] arr){
        int ret=0;
        for (int i = 0; i < arr.length; i++) {
            ret^=arr[i];
        }
        return ret;
    }
    public static void main11(String[] args) {
        int[] arr={4,1,2,1,2};
        int ret=theOnlyNum(arr);
        System.out.println(ret);
    }

    public static int[] sort1(int[] arr){
        int left=0;
        int right=1;
        while(right<arr.length){
            if(arr[left]%2==1){
                right++;
                left++;
            }else{
                int temp=arr[left];
                arr[left]=arr[right];
                arr[right]=temp;
                if(arr[left]%2==1){
                    left++;

                }
                right++;
            }
        }
        return arr;
    }

    public static int[] sort2(int[] arr){
        int left=0;
        int right=arr.length-1;
        while (left<right){
            //从数组的左边数，找到第一个偶数
            while(left<right&&arr[left]%2==1){
                left++;
            }
            //从数组的右边数，找到第一个奇数
            while(left<right&&arr[right]%2==0){
                right--;
            }
            if(left<right){
                int temp=arr[left];
                arr[left]=arr[right];
                arr[right]=temp;
                left++;
                right--;
            }
        }

        return arr;
    }
    public static void main10(String[] args) {
        int[] arr={1,2,5,7,9,4,5,18,24,6};
        int[] arr1={1,2,3,4,5,6};
        int[] ret=sort2(arr1);
        System.out.println(Arrays.toString(ret));
    }

    public static int[] bubbleSort1(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            boolean flag=false;
            for (int j = 0; j < arr.length-1-i; j++) {

                if(arr[j]>arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                    flag=true;
                }
            }
            if(flag==false){
                return arr;
            }
        }
        return arr;
    }
    public static void main9(String[] args) {
        int[] arr={4,6,8,9,1,3,2,19,3,4,5};
        int[] ret=bubbleSort1(arr);
        System.out.println(Arrays.toString(ret));
    }

    public static int binarySearch(int[] arr,int key){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int mid=(left+right)/2;
            if(arr[mid]>key){
                right=mid-1;
            }else if (arr[mid]<key){
                left=mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
    public static void main8(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8};
        int ret=binarySearch(arr,2);
        System.out.println(ret);
    }

    public static int[] transform(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i]=arr[i]*2;
        }
        return arr;
    }
    public static void main7(String[] args) {
        int[] arr={1,2,3};
        System.out.println(Arrays.toString(arr));
        int[] ret=transform(arr);
        System.out.println(Arrays.toString(ret));

    }
    public static void main6(String[] args) {
        int[][] arr1={{1,2,3},{4,5,6}};

//        for (int i = 0; i < 2; i++) {
//            for (int j = 0; j < 3; j++) {
//                System.out.print(arr1[i][j]+" ");
//            }
//            System.out.println();
//        }

        //二维数组可以被看作特殊的一维数组
        System.out.println(arr1.length);//输出二维数组的行数
        System.out.println(arr1[0].length);//输出二维数组具体行数的列数
        System.out.println(arr1[1].length);
        System.out.println(Arrays.toString(arr1[0]));//输出二维数组的第0行的所有元素
        System.out.println(Arrays.toString(arr1[1]));

        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1[i].length; j++) {
                System.out.print(arr1[i][j]+" ");
            }
            System.out.println();
        }
        System.out.print("===========");
        //使用foreach进行遍历

        System.out.println();
//        for (int[] temp: arr1) {
//            for (int x:temp) {
//                System.out.print(x+" ");
//            }
//            System.out.println();
//        }
        for (int[] temp: arr1) {
            for (int x: temp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }

        //深度打印数组（将数组转为字符串）

        String ret1=Arrays.deepToString(arr1);
        System.out.println(ret1);

        int[][] arr2=new int[][]{{1,2,3},{4,5,6}};
        int[][] arr3=new int[2][3];



        int[][] arr4=new int[2][];
    }

    public static void main5(String[] args) {
        int[] arr1={1,2,3,4,5};
        int[] arr2={1,2,3,4,5};
        System.out.println(arr1==arr2);
        //比较两个数组的内容是否一样
        boolean flag=Arrays.equals(arr1,arr2);
        System.out.println(flag);

        int[] ret=new int[10];
        //初始化数组
        Arrays.fill(ret,1,7,10);
        System.out.println(Arrays.toString(ret));
    }

    public static int[] copyArr(int[] arr){
        int[] copy=new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            copy[i]=arr[i];
        }
        return copy;
    }

    public static void main4(String[] args) {
        int[] arr={1,2,3,4,5};
        int[] copy=copyArr(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(copy));
        //数组拷贝
        int[] copy1=Arrays.copyOf(arr,arr.length);
        System.out.println(Arrays.toString(copy1));
        //拷贝一部分
        int[] copy2=Arrays.copyOfRange(arr,1,4); //  [1,4)
        System.out.println(Arrays.toString(copy2));
    }

    public static int[] myreserve(int[] arr){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int temp=arr[left];
            arr[left]=arr[right];
            arr[right]=temp;
            left++;
            right--;
        }

        return arr;
    }
    public static void main3(String[] args) {
        int[] arr={1,2,3,4,5};
        System.out.println(Arrays.toString(arr));

        int[] ret= myreserve(arr);
        System.out.println(Arrays.toString(ret));
    }

    //冒泡排序
    public static void bubbleSort(int[] array){
        //i表示趟数，比如，五个数据，最多比四次
        for (int i = 0; i < array.length-1; i++) {
            //j表示比较的次数
            boolean flag=false;   //优化:如果经过某一次排序后，已经有序，则后面就不需要交换了
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int temp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;

                    flag=true;
                }
            }
            //如果经过一趟排序后，flag仍然为false，说明一次也没有进入if,说明数据已经有序了，所以直接返回
            if(flag==false){
                return;
            }
        }
    }
    public static void main2(String[] args) {
        int[] array={1,5,8,2,3,0,4};
        System.out.println("排序前的数据"+ Arrays.toString(array));

        bubbleSort(array);

        System.out.println("排序后的数据"+Arrays.toString(array));
    }

    public static void main1(String[] args) {
        System.out.println("hello world");
    }
}
